﻿using MediatR;
using Process.Api.Application.Command.BOM;
using Process.BLL;
using Process.DAL;
using Process.ErrorCod;
using Process.Model;

namespace Process.Api.Application.Handler.BOM
{
    public class DetailGoodsinfoHandler : IRequestHandler<DetailGoodsinfoCommand, ApiResult<Goodsinfo>>
    {
        private readonly IProcessRepository<Goodsinfo> goodsinfoRepo;

        public DetailGoodsinfoHandler(IProcessRepository<Goodsinfo> goodsinfoRepo)
        {
            this.goodsinfoRepo = goodsinfoRepo;
        }
        /// <summary>
        /// 查询物品详情
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<ApiResult<Goodsinfo>> Handle(DetailGoodsinfoCommand request, CancellationToken cancellationToken)
        {
           var result = new ApiResult<Goodsinfo>();
            var entity = goodsinfoRepo.GetAllAsync().FirstOrDefault(x => x.Id == request.Id && x.IsDelete == false);
            if (entity == null)
            {
                result.Code = ErrorStatus.Error;
                result.Message = "未找到对应物品信息";
                return Task.FromResult(result);
            }

            result.Code = ErrorStatus.Success;
            result.Data = entity;
            result.Message = "获取成功";
            return Task.FromResult(result);
        }
    }
}
